import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { CopySkillInfo } from "../../../resource/info/CopySkillInfo";
import { CopyType } from "../CopyType";
import { GameProxy } from "../../../mvc/GameProxy";
import { SPoint } from "../../../../../Message/Public/SPoint";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameController } from "../../../mvc/GameController";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { ItemData } from "../../../resource/info/ItemData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class SixtySkillSmeltCellRenderer
    
    export  class SixtySkillSmeltCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._materialLabels = new Vector.<GLabel>();
            this.initStyle();
            this.createChildren();
            this.mouseChildren = true;
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc3=null;
            var loc1=ResouceConst.getScaleBitmap("PackItemBg");
            loc1.x = 11;
            loc1.y = 4;
            this.addChild(loc1);
            ObjCreate.createBg(8, 67, 314, 2, this, ImagesConst.SplitLine);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.x = loc1.x + 3;
            this._baseItem.y = loc1.y + 3;
            this._baseItem.isShowLock = false;
            this.addChild(this._baseItem);
            this._nameLabel = ObjCreate.createLabel("", 0, loc1.y + 41, 65, 20, flash.text.TextFormatAlign.CENTER, this, false, 16776960);
            this._nameLabel.drawNow();
            var loc2=0;
            while (loc2 < 4) 
            {
                loc3 = ObjCreate.createLabel("", loc2 * 64 + 65, 4, 70, 20, flash.text.TextFormatAlign.LEFT, this, false, 16776960);
                loc3.drawNow();
                this._materialLabels.push(loc3);
                ++loc2;
            }
            this._descText = ObjCreate.createTextField("", 65, 24, 200, 45, this);
            this._descText.filters = [];
            this._descText.wordWrap = true;
            this._smeltBtn = ObjCreate.createGButton(Language.getString(60091), 268, 28, 49, 26, this);
            this._smeltBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSmeltBtnClick);
            this._smeltBtn.drawNow();
            return;
        }

        /* internal  */onSmeltBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                loc1 = data as CopySkillInfo;
                var loc2=this._copyCode;
                switch (loc2) 
                {
                    case CopyType.SIXTY_COPY:
                    {
                        GameProxy.copy.sixtyCopyOperation(false, loc1.itemCode, [], new SPoint(), this.onSmeltSuccess);
                        break;
                    }
                    case CopyType.CROSS_ARYADEVA_SECRET_COPY:
                    {
                        GameProxy.copy.useItemInCrossSecret(false, loc1.itemCode, [], new SPoint(), this.onSmeltSuccess);
                        break;
                    }
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossAryadevaSecretCopyRemoveGuideStepSecond));
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossAryadevaSecretCopyAddGuideStepThirdly));
            return;
        }

        /* internal  */onSmeltSuccess(arg1): void
        {
            var loc2=null;
            var loc1=this.localToGlobal(new Object /* flash.geom.Point */(this._baseItem.x, this._baseItem.y));
            var loc3=this._copyCode;
            switch (loc3) 
            {
                case CopyType.SIXTY_COPY:
                {
                    loc2 = GameController.copy.sixtyCopy.sixtyCopyView.getSkillPropPointByCode(this._baseItem.itemData.itemCode);
                    break;
                }
                case CopyType.CROSS_ARYADEVA_SECRET_COPY:
                {
                    loc2 = GameController.copy.crossAryadevaSecretCopy.crossAryadevaSecretCopyView.getSkillPropPointByCode(this._baseItem.itemData.itemCode);
                    break;
                }
            }
            FlyToNavbarTool.flyToAnyPoint(this._baseItem.bitmapdata, loc1, loc2, this.onFlyEnd);
            return;
        }

        /* internal  */onFlyEnd(arg1: Object /* flash.display.Bitmap */): void
        {
            if (arg1 && arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=false;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=0;
            super.data = arg1;
            if (data) 
            {
                loc1 = data as CopySkillInfo;
                if (loc1) 
                {
                    this._copyCode = loc1.copyCode;
                }
                this._baseItem.itemData = new ItemData(loc1.itemCode);
                this._nameLabel.htmlText = HTMLUtil.addColor(this._baseItem.itemData.name, "#FFFF00");
                this._descText.htmlText = HTMLUtil.addColor(this._baseItem.itemData.itemInfo.item.descStr, GlobalStyle.color1);
                loc2 = true;
                loc6 = 0;
                while (loc6 < 4) 
                {
                    if (loc6 < loc1.formula.length) 
                    {
                        loc3 = loc1.formula[loc6]["itemData"] as ItemData;
                        if (loc1.getMaterialNeed(loc3.itemCode) <= Cache.instance.copy.getNumByCodeAndCopyCode(loc3.itemCode, this._copyCode)) 
                        {
                            loc5 = "#FFFF00";
                        }
                        else 
                        {
                            loc2 = false;
                            loc5 = "#FF0000";
                        }
                        this._materialLabels[loc6].htmlText = HTMLUtil.addColor(loc3.itemInfo.item.name.substr(0, 1) + "*" + loc1.getMaterialNeed(loc3.itemCode), loc5);
                    }
                    else 
                    {
                        this._materialLabels[loc6].htmlText = "";
                    }
                    ++loc6;
                }
                if (loc2) 
                {
                    this._smeltBtn.enabled = true;
                    this._smeltBtn.drawNow();
                }
                else 
                {
                    this._smeltBtn.enabled = false;
                    this._smeltBtn.drawNow();
                }
            }
            return;
        }

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_descText: Object /* flash.text.TextField */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_materialLabels: Vector.<GLabel>;

        /* internal */ /* var */_smeltBtn: GButton;

        /* internal */ /* var */_copyCode: int;
    }
